package com.top.mall.main.mine

import android.app.Activity
import android.content.Intent
import androidx.lifecycle.LifecycleOwner
import com.module.lemlin.http.Status
import com.module.lemlin.owner.OwnerViewModeActivity
import com.top.mall.R
import com.top.mall.base.BaseViewModel
import com.top.mall.main.mine.adapter.ShopAddressAdapter
import kotlinx.android.synthetic.main.activity_mine_address.*

class MineShopActivity : OwnerViewModeActivity<BaseViewModel>() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, MineShopActivity::class.java)
            activity.startActivity(intent)
        }
    }

    private val shopAddressAdapter: ShopAddressAdapter = ShopAddressAdapter()

    override fun viewModel(): BaseViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_mine_address

    override fun stateBar(): StatusBar {
        return StatusBar(color = R.color.colorWhite, view = flMineAddressBar)
    }

    override fun initView() {

        imageViewBack.setOnClickListener { finish() }
        rvMineAddressBody.adapter = shopAddressAdapter
    }

    override fun initData() {
        viewModel.userShop()
    }

    override fun initViewMode() {
        viewModel.userShopLiveData.observe(this as LifecycleOwner, { response ->
            if (response.status != Status.SUCCESS) {
                return@observe
            }
            val data = response.data?.data
                ?: return@observe
            shopAddressAdapter.setNewInstance(data)
        })
    }

}